﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC3MusicStore.Models;

namespace MVC3MusicStore.Controllers
{
    public class StoreController : Controller
    {
        //
        // GET: /Store/

        MusicStoreEntities db = new MusicStoreEntities();

        /// <summary>
        /// 列出商店中唱片的分类
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //return View();
            //return "Hello Store.Index()";
            //var genreModels = new List<Genre>  
            //{  
            //    new Genre { Name = "Disco"},  
            //    new Genre { Name = "Jazz"},  
            //    new Genre { Name = "Rock"}  
            //};
            //return View(genreModels);
            var genreModels = db.Genres.ToList();
            return View(genreModels);
        }

        /// <summary>
        /// 手机端列出商店中唱片的分类
        /// </summary>
        /// <returns></returns>
        public ActionResult mIndex()
        {
            var genreModels = db.Genres.ToList();
            return View(genreModels);
        }


        /// <summary>
        /// 浏览商店中某个分类中的唱片列表
        /// </summary>
        /// <param name="genre"></param>
        /// <returns></returns>
        public ActionResult Browse(string genre)
        {
            //return "Hello Store.Browse()";
            //string message = HttpUtility.HtmlEncode("Store.Browse(), Genre = " + genre);
            //return message;
            //var genreModel = new Genre { Name = genre };
            //return View(genreModel);
            var genreModel = db.Genres.Include("Albums").Single(g => g.Name == genre); 
            return this.View(genreModel);
        }

        /// <summary>
        /// 手机端浏览商店中某个分类中的唱片列表
        /// </summary>
        /// <param name="genre"></param>
        /// <returns></returns>
        public ActionResult mBrowse(string genre)
        {
            var genreModel = db.Genres.Include("Albums").Single(g => g.Name == genre);
            return this.View(genreModel);
        }


        /// <summary>
        /// 显示特定唱片的详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            //return "Hello Store.Details()";
            //string message = "Store.Details(), ID = " + id;
            //return message;
            //var albumModel = new Album { Title = "Album " + id };
            //return View(albumModel);
            var album = db.Albums.Find(id);
            return View(album);
        }

        /// <summary>
        /// 手机显示特定唱片的详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult mDetails(int id)
        {
            var album = db.Albums.Find(id);
            return View(album);
        }

        //
        // GET: /Store/GenreMenu
        [ChildActionOnly]
        public ActionResult GenreMenu()
        {
            var genres = db.Genres.ToList();
            return PartialView(genres);
        }
    }
}
